﻿





using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace Serialization.Script
{
    /// <summary>
    /// This class holds events pending to happen.
    /// </summary>
    public class LevelScript
    {
        private List<ScriptedEvent> events;

        private float elapsedTime = 0;

	    public List<ScriptedEvent> getPendingEvents()
	    {
            bool finished = false;
            List<ScriptedEvent> pendingEvents = new List<ScriptedEvent>();
            while (0 < events.Count && !finished) 
            {
                finished = events[0].eventTime > elapsedTime;
                if (!finished) 
                {
                    pendingEvents.Add(events[0]);
                    events.RemoveAt(0);
                }
            }
            return pendingEvents;
	    }

        public void Update(GameTime time)
        {
            elapsedTime += (float)time.ElapsedGameTime.TotalMilliseconds;
        }

	    public LevelScript(List<ScriptedEvent> events)
	    {
            this.events = events;
	    }

        /// <summary>
        /// Returns the number of enemies contained in all events held by this class.
        /// </summary>
        /// <returns></returns>
        public int getNumberOfEnemies()
        {
            int number = 0;
            foreach (ScriptedEvent e in events)
            {
                number += e.getNumberOfEnemies();
            }
            return number;
        }

    }
}

